package thread.thread_local;

/**
 * @program: Multhread
 * @description: threadlocal 是一个map
 * @author: zhanghz001
 * @create: 2021-03-05 10:23
 **/
public class ThreadLocalDemo implements Runnable {
    
    public static void main(String[] args) {
        ThreadLocalDemo demo = new ThreadLocalDemo();
        new Thread(demo).start();
        new Thread(demo).start();
        
    }
    
    @Override
    public void run() {
        ThreadLocal<Integer> local = new ThreadLocal<>();
        for (int i = 0; i < 3; i++) {
            local.set(i);
            System.out.println(Thread.currentThread().getName() + ",value="
                    + local.get());
        }
        
    }
}
